<template>
  <view class="wrapper row">
    <block v-if="loginFlag">
      <view class="search row flex-center pd_l_30 pd_r_30" style="justify-content: space-between;">
        <u-input v-model="value" class="flex-1 fon4-24 pd_l_30 pd_r_30"
                 confirm-type="search"
                 @confirm="filter"
                 :height="50" placeholder="请输入院校名称进行搜索"/>
        <view class="btn color-active" @click="filter">搜索</view>
      </view>
      <view class="table">
        <view class="th bg-f2f2f2 row cont-center flex-around">
          <view class="td color-active font-24 pd_t_20 pd_b_20 flex-1">专业排名</view>
          <view class="td color-active font-24 pd_t_20 pd_b_20 flex-1">院校名称</view>
          <view class="td color-active font-24 pd_t_20 pd_b_20 flex-1">首选科目要求</view>
          <view class="td color-active font-24 pd_t_20 pd_b_20 flex-1">再选科目要求</view>
        </view>
        <block v-for="(item, index) in list" :key="index" v-if="!item.hidden">
          <view class="th row cont-center flex-around">
            <view class="td flex-1 font-24 pd_t_20 pd_b_20 ">{{item.specialtySort || '-'}}</view>
            <navigator :url="`/pages/explore/school_info?id=${item.schoolId}`"
                       v-if="item.schoolId"
                       class="td flex-1 font-24 pd_t_20 pd_b_20 color-active">
              {{item.schoolName}}
            </navigator>
            <view class="td flex-1 font-24 pd_t_20 pd_b_20" v-else>{{item.schoolName}}</view>
            <view class="td flex-1 font-24 pd_t_20 pd_b_20 ">{{item.firstCondition || '-'}}</view>
            <view class="td flex-1 font-24 pd_t_20 pd_b_20 ">{{item.secCondition || '-'}}</view>
          </view>
          <view class="th row cont-center flex-around bg-f2f2f2">
            <view class="td flex-1 font-24 pd_t_20 pd_b_20 ">往年录取分</view>
            <view class="td flex-1 font-24 pd_t_20 pd_b_20 ">
              <block v-if="item.compassRecruitScoreList[0]">
              {{item.compassRecruitScoreList[0].lowestScore || ''}} <text v-if="item.compassRecruitScoreList[0].year">({{item.compassRecruitScoreList[0].year}})</text>
              </block>
              <block v-if="!item.compassRecruitScoreList[0] && !item.compassRecruitScoreList[1] && !item.compassRecruitScoreList[2]">
                -
              </block>
            </view>
            <view class="td flex-1 font-24 pd_t_20 pd_b_20 ">
              <block v-if="item.compassRecruitScoreList[1]">
                {{item.compassRecruitScoreList[1].lowestScore || ''}} <text v-if="item.compassRecruitScoreList[1].year">({{item.compassRecruitScoreList[1].year}})</text>
              </block>
            </view>
            <view class="td flex-1 font-24 pd_t_20 pd_b_20 ">
              <block v-if="item.compassRecruitScoreList[2]">
                {{item.compassRecruitScoreList[2].lowestScore || ''}} <text v-if="item.compassRecruitScoreList[2].year">({{item.compassRecruitScoreList[2].year}})</text>
              </block>
            </view>
          </view>
        </block>
      </view>
      <view class="color-999 text-cent font-20 u-p-b-30">数据仅供参考，最终以高校与考试院公布为准！</view>
    </block>
    <view v-else style="height: 100%">
      <go_login></go_login>
    </view>
  </view>
</template>

<script>
  import {request} from "../../util/api";
  import mixins from "./mixins";
  import go_login from "@/components/go_login";
  import {getCurrentFullPath} from '../../util/util'

  export default {
    mixins: [mixins],
    components: {
      go_login
    },
    onLoad(option) {
      if (option.code && this.loginFlag) {
        this.getDetail(option)
      }
    },

    data() {
      return {
        list: [],
        value: ''
      }
    },

    methods: {
      getDetail(option) {
        request({
          url: '/system/wx/CompassChangeSubject/getSubject',
          token: true,
          data: {
            specialtyCode: option.code,
            admissionsAddress: option.admissionsAddress,
            year: option.year == 'undefined' ? '' : option.year,
            uOrS: option.uOrS == 'undefined' ? '' : option.uOrS
          }
        }).then(res => {
          this.list = res.data
          this.list.sort(this.compare('specialtySort'))
        })
      },

      compare(property){
        return function(a,b){
          var value1 = a[property] || 999999999;
          var value2 = b[property] || 999999999;
          return value1 - value2;
        }
      },

      filter() {
        this.list.forEach(item => {
          if (item && !item.schoolName.includes(this.value)) {
            this.$set(item, 'hidden', true)
          } else {
            this.$set(item, 'hidden', false)
          }
        })
      }
    },

    onShareAppMessage(res) {
      return {
        path: getCurrentFullPath()
      }
    }
  }
</script>

<style scoped lang="scss">
  .wrapper {
    flex-direction: column;
    height: 100%;
    .search {
      width: 100%;
      background: rgba(249, 249, 249, 100);
      padding-top: 20upx;
      padding-bottom: 20upx;

      .flex-1 {
        background: #fff;
        border-radius: 25upx;
        margin-right: 20upx;
      }
    }

    .table {
      width: 92%;
      margin: 0 auto;
      margin-top: 30upx;
      margin-bottom: 30upx;

      .td, .th {
        text-align: center;
      }
    }
  }
</style>
